home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok44.lha
/
Length
/
Length.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
3KB
|
119 lines
(**********************************************************************
:Program. Length
:Contents. Gibt die Länge eines Directorys aus
:Author. Steffen Reith
:Address. Hessenstr. 64, D-8700 Würzburg
:Language. Modula-2
:Translator. M2Amiga A+L V3.2d
**********************************************************************)
(* $R- $F- *)
MODULE Length;
(* Length V1.2 5.8.1989 *)
(* New with HomeDirLength 22.1.1990 *)
FROM Arguments IMPORT NumArgs,GetArg;
FROM Dos IMPORT Examine,ExNext,Lock,accessRead,FileLockPtr,FileLock,
FileInfoBlock,FileInfoBlockPtr,UnLock;
FROM InOut IMPORT WriteInt,WriteString,WriteLn,Write;
FROM SYSTEM IMPORT ADR,ADDRESS;
FROM Arts IMPORT Assert;
FROM Heap IMPORT Allocate,Deallocate;
FROM Str IMPORT Concat,Length;
CONST Len=01FFH;
TYPE String=ARRAY[0..Len] OF CHAR;
VAR Name,PrgName:String;
NDir,NFile,N,L:INTEGER;
PROCEDURE DLength(VAR Name:ARRAY OF CHAR;N:INTEGER):LONGINT;
VAR FilePtr,Old:FileLockPtr;
InfoPtr:FileInfoBlockPtr;
Summe,Size:LONGINT;
Path:String;
Command1,Command2:ARRAY[0..3] OF CHAR;
BEGIN
Summe:=0;
Allocate(ADDRESS(InfoPtr),SIZE(FileInfoBlock));
(* Speicherblock wird im Fehlerfall von Storage zurueckgegeben *)
Assert(InfoPtr#NIL,ADR('Cant allocate FileInfoBlock !!'));
FilePtr:=Lock(ADR(Name),accessRead);
Assert(FilePtr#NIL,ADR('Wrong directory !!'));
Assert(Examine(FilePtr,InfoPtr),ADR('Can not Examine File !!'));
INC(NDir);
Assert(InfoPtr^.dirEntryType>=0,ADR('Only directories are allowed !!'));
Command1:=' [1m';Command1[0]:=CHAR(27);
Command2:=' [0m';Command2[0]:=CHAR(27);
LOOP
IF NOT(ExNext(FilePtr,InfoPtr)) THEN EXIT END;
(* Dateiinformationen holen !! *)
IF (InfoPtr^.dirEntryType>0) THEN
Path:='';
Concat(Path,Name);
IF ((Name[0]#CHAR(0)) AND ((N>1) OR (Name[Length(Name)-1]#':'))) THEN
Concat(Path,'/')
END;
Concat(Path,InfoPtr^.fileName);
Size:=DLength(Path,N+1);
WriteString(Command1);
WriteString(Path);
WriteString(Command2);
WriteString(' ==> ');
WriteInt(Size,0);WriteLn;
Summe:=Summe+Size
ELSE
Summe:=Summe+InfoPtr^.size;
INC(NFile)
END
END;
UnLock(FilePtr);
Deallocate(ADDRESS(InfoPtr));
RETURN Summe
END DLength;
PROCEDURE PrintErg(VAR Name:String);
VAR Size:LONGINT;
BEGIN
Size:=DLength(Name,1);
WriteLn;
WriteString('There are ');
WriteInt(Size,0);
WriteString(' Bytes in ');
WriteInt(NDir,0); (* Global *)
WriteString(' directories and ');
WriteInt(NFile,0); (* Global *)
WriteString(' Files !!');
WriteLn
END PrintErg;
BEGIN
NDir:=0;
NFile:=0;
N:=NumArgs();
IF (N=1) THEN
GetArg(1,Name,L);
IF Name[0]='?' THEN
GetArg(0,PrgName,L);
WriteString(PrgName);
WriteString(' DIR');
WriteLn;
ELSE
PrintErg(Name)
END
ELSIF (N=0) THEN
Name:='';
PrintErg(Name);
ELSE
WriteString('Illegal number of arguments !!');WriteLn
END;
END Length.